package com.zymail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zymail.bean.ZyComment;
import com.zymail.bean.ZyGood;
import com.zymail.mapper.ZyCommentMapper;
import com.zymail.service.ZyCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Dorado
 * @since 2021-04-12
 */
@Service
public class ZyCommentServiceImpl extends ServiceImpl<ZyCommentMapper, ZyComment> implements ZyCommentService {

    @Autowired
    ZyCommentService commentService;

    @Override
    public List<ZyComment> getall(Integer id) {
        QueryWrapper<ZyComment> wrapper = new QueryWrapper<>();
        wrapper.eq("good_id", id);
        wrapper.orderByDesc("time");
        return commentService.list(wrapper);
    }

    @Override
    public List<ZyComment> gettwo(Integer id) {
        List<ZyComment> comments = getall(id);
        List<ZyComment> res = new ArrayList<>();
        for(int i = 0; i < Math.min(comments.size(), 2); i++){
            res.add(comments.get(i));
        }
        return res;
    }


}
